#include<iostream>
#include<assert.h>
#include <iterator>
using namespace std;
typedef int STDateType;
typedef struct stack {
	int capacity;
	int top;
	STDateType* st;
}stack;
void stackinit(stack*ps);

void stackdestroy(stack* ps);

void stackpush(stack* ps, STDateType x);	

void stackpop(stack* ps);

STDateType stacktop(stack* ps);

STDateType stacksize(stack* ps);

bool stackempty(stack* ps);

void stackinit(stack* ps)
{
	ps->st = (STDateType*)malloc(sizeof(STDateType)*4);
	if(ps->st==NULL)
	{
		perror("malloc failed");
		return;
	}
	ps->capacity = 4;
	ps->top = 0;
}

void stackdestroy(stack* ps)
{
	free(ps->st);
	ps->st = NULL;
	ps->top = 0;
	ps->capacity = 0;
}

void stackpush(stack* ps, STDateType x)
{
	if (ps->top-1 == ps->capacity)
	{
		STDateType* tmp = (STDateType*)realloc(ps->st, sizeof(STDateType) * ps->capacity * 2);
		if (tmp == NULL)
		{
			perror("realloc faild");
			return;
		}
		else
			ps->st = tmp;
	}
	ps->st[ps->top++] = x;
}

void stackpop(stack* ps)
{
	if (stackempty(ps))return;
	ps->top--;
}

STDateType stacktop(stack* ps)
{
	assert(ps);
	return ps->st[ps->top-1];
}

STDateType stacksize(stack* ps)
{
	return ps->top - 1;
}

bool stackempty(stack* ps)
{
	return ps->top == 0;
}

typedef struct {
    stack  pop_s;
    stack  push_s;
} MyQueue;


MyQueue* myQueueCreate() {
    MyQueue *queue=(MyQueue*)malloc(sizeof(MyQueue));
    stackinit(&queue->pop_s) ;
    stackinit(&queue->push_s) ;
    return queue;
}

void myQueuePush(MyQueue* obj, int x) {
    stackpush(&obj->push_s,x);
}

int myQueuePop(MyQueue* obj) {
    if(stackempty(&obj->pop_s))
    {
        if(!stackempty(&obj->push_s))
        {
            while(!stackempty(&obj->push_s))
            {
                stackpush(&obj->pop_s,stacktop(&obj->push_s));
                stackpop(&obj->push_s);
            }
        }
        else return NULL;
    }
    int x=stacktop(&obj->pop_s);
    stackpop(&obj->pop_s);
    return x;
}

int myQueuePeek(MyQueue* obj) {
    if(stackempty(&obj->pop_s))
    {
        if(!stackempty(&obj->push_s))
        {
            while(!stackempty(&obj->push_s))
            {
                stackpush(&obj->pop_s,stacktop(&obj->push_s));
                stackpop(&obj->push_s);
            }
        }
        else return NULL;
    }
    int x=stacktop(&obj->pop_s);
    return x;
}

bool myQueueEmpty(MyQueue* obj) {
    return stackempty(&obj->pop_s)&&stackempty(&obj->push_s);
}

void myQueueFree(MyQueue* obj) {
    stackdestroy(&obj->pop_s);
    stackdestroy(&obj->push_s);
    free(obj);
    obj=NULL;
}